<!--
 * @Descripttion: vue and node-bs
 * @Author: weijunliang-jul
 * @Date: 2021-02-04 10:49:56
 * @LastEditors: weijunliang-jul
 * @LastEditTime: 2021-03-08 15:41:58
-->
<template>
  <el-form>
    <el-form-item label="账户名">
      <el-input
        disabled
        v-model.trim="user.name"
      />
    </el-form-item>
    <el-form-item label="旧密码">
      <el-input
        show-password
        v-model.trim="oldPassword"
      />
    </el-form-item>
    <el-form-item label="新密码">
      <el-input
        show-password
        v-model.trim="newPassword"
      />
    </el-form-item>
        <el-form-item label="确认新密码">
      <el-input
        show-password
        v-model.trim="a_newPassword"
      />
    </el-form-item>
    <el-form-item>
      <el-button
        type="primary"
        @click="updatePassword"
      >修改</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
import { updatePasswordApi } from "../../../api/common-api/personInformation";
export default {
  props: {
    user: {
      type: Object,
      default: () => {
        return {
          name: "",
        };
      },
    },
  },
  data() {
    return {
      oldPassword: "",
      newPassword: "",
      a_newPassword: ""
    };
  },
  methods: {
    updatePassword() {
      if (!this.oldPassword && !this.newPassword) {
        this.$message({
          message: "输入框不能为空",
          type: "warning",
        });
      } else if (this.newPassword != this.a_newPassword) {
        this.$message({
          message: "错误，确认密码不一致",
          type: "warning",
        });
      } else if (this.oldPassword.length != 6 && this.newPassword.length != 6) {
        this.$message({
          message: "密码必须6位数以上哦~",
          type: "warning",
        });
      } else {
        updatePasswordApi(this.oldPassword, this.newPassword).then((res) => {
          this.$message({
            message: "修改成功, 下次登录请使用新密码",
            type: "success",
          });
          this.oldPassword = ''
          this.newPassword = ''
          this.a_newPassword = ''
        })
      }
    },
  },
};
</script>
